<?php

include_once("connexion.php");
echo $_SESSION["nom"];
$query="SELECT * FROM Pays";
$pays=mysqli_query($bdd,$query);
$query="SELECT * FROM Type_Biens";
$type=mysqli_query($bdd,$query);
$query="SELECT * FROM Ville";
$ville=mysqli_query($bdd,$query);



if(isset($_POST["publier"]) && isset($_SESSION['co'])){
	$id=$_SESSION['id'];
	$adresse=$_POST["adresse"];
	$description=$_POST["description"];
	$ville=$_POST["ville"];
	$type=$_POST["bien"];
	$pays=$_POST["pays"];
	$cp=$_POST["code_postal"];
	$date1=$_POST["annee_debut"]."/".$_POST["mois_debut"]."/".$_POST["jour_debut"];
	$date2=$_POST["annee_fin"]."/".$_POST["mois_fin"]."/".$_POST["jour_fin"];
	$prix1=$_POST["prix_journee"];
	$prix2=$_POST["prix_semaine"];
	$surface=$_POST["surface"];
	$photo=$_POST["prix_journee"];
	
	$query="INSERT INTO Biens(Id,Adresse,Description,Id_Ville,Id_Type_Bien,Id_Pays,CP,Date_Debut,Date_Fin,Id_Bailleur,Prix_Journee,Prix_Semaine,Surface,Etat) 
		VALUES('',
		'".$adresse."', 
		'".$description."',
		'".$ville."',
		'".$type."',
		'".$pays."',
		'".$cp."',
		'".$date1."',
		'".$date2."',
		'".$id."',
		'".$prix1."',
		'".$prix2."',
		'".$surface."',
		'0');";
	$resultat=mysqli_query($bdd,$query);	//on insert les données reçus par post dans les champs de la table
	if($resultat == false){
		echo "Impossible de sauvegarder en Base <br />";
	}
	if($_SESSION["co"]==30){
		
		$query="UPDATE `Freebed`.`User` SET  `Id_spe` =  '1' WHERE  `User`.`Id` ='".$_SESSION[id]."'";
		$resultat=mysqli_query($bdd,$query); //on change l'etat d'utilisateur en bailleur
		}
	
	}
	else if(isset($_POST["valider"]) && !isset($_SESSION['co'])){
	header("location:connexion_user.php");
	}

?>

<!DOCTYPE html>

<html>
	<head>
		<link rel="stylesheet" type="text/css" href="publication.css"/>
		<title>Louer votre bien</title>
		<meta charset="UTF-8" />
		<meta http-equiv="Content-Type" content="charset=UTF-8" />
	</head>

	<body>

		<header>
			
			<p>  </p>

		</header>
		<center>
		<br />
<div id = "menu" >

<a  href="index.php"/> Index </a>
<a  href="index2.php"/>Inscription </a>
<a  href="user0.php"/>  Page user </a>
<a  href="recherche_biens.php"/>   Recherche </a>
<a  href="publication2.php"/>   Deposer Bien </a>

<right>
<form id="formulaire" method="post" action="Connexion_user.php">
Identification : 


<input type="text" id="nom" name="nom" value="" size="5" />
Mot de passe :

<input type="password" id="pass" name="pass" value="" size="5"/>
<input type="submit" id="ok" name="ok" value="ok" />



</form>
</center>
      <div class="sous_banniere">

				<div class="champ_titre">

					<span>

PUBLIEZ VOTRE ANNONCE :)
					</span>

				</div>

			</div>	
			

	<div class="background_recherche">

		<div class="champ_recherche">

			<form action="" method="post">

				<div id="type_bien"> <h1> Type de bien </h1> <select name="bien"> 

				<<?php
				while($data = mysqli_fetch_array($type)){
					echo "<option value='".$data["Id"]."' >". utf8_encode($data["Libelle"])." </option>";
					
					
					}
				?>

 				</select> </div>

 				<div id="pays"> <h2 class="titre"> Pays </h2> <select name="pays">

 				<?php
				while($data = mysqli_fetch_array($pays)){
					echo "<option value='".$data["Id"]."' >". utf8_encode($data["Nom"])." </option>";
					
					
					}
				?>

 				</select> </div>

 				<div id="ville"> <h2> Ville </h2> <select name="ville">

 				<?php
				while($data = mysqli_fetch_array($ville)){
					echo "<option value='".$data["Id"]."' >". utf8_encode($data["Nom"])." </option>";
					
					
					}
				?>

 				</select> </div>

 				<div id="cp">

 					<h2> Code Postal </h2> 

 					<input type="text" name="code_postal" id="code_postal" value="" >

 				</div>

 				<div id="adresse">

 					<h2> Adresse </h2>

					<input type="text" name="adresse" id="adresse" value="" >

				</div>

				<div id="date_debut"><h2> Date de Début </h2> <select name="jour_debut">

				<option value="1">1</option> 
  				<option value="2">2</option>
 				<option value="3">3</option>
 				<option value="4">4</option>
 				<option value="5">5</option> 
  				<option value="6">6</option>
 				<option value="7">7</option>
 				<option value="8">8</option>
 				<option value="9">9</option> 
  				<option value="10">10</option>
 				<option value="11">11</option>
 				<option value="12">12</option>
 				<option value="13">13</option> 
  				<option value="14">14</option>
 				<option value="15">15</option>
 				<option value="16">16</option>
 				<option value="17">17</option> 
  				<option value="18">18</option>
 				<option value="19">19</option>
 				<option value="20">20</option>
 				<option value="21">21</option> 
  				<option value="22">22</option>
 				<option value="23">23</option>
 				<option value="24">24</option>
 				<option value="25">25</option> 
  				<option value="26">26</option>
 				<option value="27">27</option>
 				<option value="28">28</option>
 				<option value="29">29</option> 
  				<option value="30">30</option>
 				<option value="31">31</option>

 				</select>

 				<select name="mois_debut">

 				<option value="1">janvier</option> 
  				<option value="2">février</option>
 				<option value="3">mars</option>
 				<option value="4">avril</option>
 				<option value="5">mai</option>
 				<option value="6">juin</option>
 				<option value="7">juillet</option>
 				<option value="8">août</option>
 				<option value="9">septembre</option>
 				<option value="10">octobre</option>
 				<option value="11">novembre</option>
 				<option value="12">décembre</option>

 				</select>

 				<select name="annee_debut">

 				<option value="1">2014</option> 
  				<option value="2">2015</option>
 				<option value="3">2016</option>
 				<option value="4">2017</option>

 				</select> </div>

 				<div id="date_fin"><h2> Date de fin </h2> <select name="jour_fin">

				<option value="1">1</option> 
  				<option value="2">2</option>
 				<option value="3">3</option>
 				<option value="4">4</option>
 				<option value="5">5</option> 
  				<option value="6">6</option>
 				<option value="7">7</option>
 				<option value="8">8</option>
 				<option value="9">9</option> 
  				<option value="10">10</option>
 				<option value="11">11</option>
 				<option value="12">12</option>
 				<option value="13">13</option> 
  				<option value="14">14</option>
 				<option value="15">15</option>
 				<option value="16">16</option>
 				<option value="17">17</option> 
  				<option value="18">18</option>
 				<option value="19">19</option>
 				<option value="20">20</option>
 				<option value="21">21</option> 
  				<option value="22">22</option>
 				<option value="23">23</option>
 				<option value="24">24</option>
 				<option value="25">25</option> 
  				<option value="26">26</option>
 				<option value="27">27</option>
 				<option value="28">28</option>
 				<option value="29">29</option> 
  				<option value="30">30</option>
 				<option value="31">31</option>

 				</select>

 				<select name="mois_fin">

 				<option value="1">janvier</option> 
  				<option value="2">février</option>
 				<option value="3">mars</option>
 				<option value="4">avril</option>
 				<option value="5">mai</option>
 				<option value="6">juin</option>
 				<option value="7">juillet</option>
 				<option value="8">août</option>
 				<option value="9">septembre</option>
 				<option value="10">octobre</option>
 				<option value="11">novembre</option>
 				<option value="12">décembre</option>

 				</select>

 				<select name="annee_fin">

 				<option value="1">2014</option> 
  				<option value="2">2015</option>
 				<option value="3">2016</option>
 				<option value="4">2017</option>

 				</select> </div>

 				<div id="prix_journee"> <h2>Prix à la journée</h2>

 					<input type="text" name="prix_journee" id="prix_journee" value="">

 				</div>


 					<div id="prix_semaine"> <h2>Prix à la semaine</h2>

 						<input type="text" name="prix_semaine" id="prix_semaine" value="">

 					</div>


 						<div id="surface"> <h2>Surface en m²</h2>

 							<input type="text" name="surface" id="surface" value="">

 						</div>


 				<div id="description"> <h3 class="description"> Description </h3>

 				<textarea id="description" name="description" > </textarea> <br><br> </div>

 				<input type="submit" name="publier" id="publier" value="Publier">

		</div>

	</div>

			<div class="footer">

				<p> </p>

			</div>




	</body>

</html>
